package aaaAddr;

import java.util.List;

import jdk.nashorn.internal.ir.Terminal;

import com.attilax.json.AtiJson;
import com.registry.RegistryKey;
import com.registry.RegistryValue;

/**
 * @author digdeep@126.com
 */
public class RegstryUtilX
{
    //"HKEY_LOCAL_MACHINE"
    public static final RegistryKey LOCALMACHINE = RegistryKey.getRootKeyForIndex(RegistryKey.HKEY_LOCAL_MACHINE_INDEX);
    
    // "HKEY_LOCAL_MACHINESystemCurrentControlSetControlTerminal ServerWinStationsRDP-Tcp"
    public static final RegistryKey rdpKey=null;
    //= new RegistryKey(LOCALMACHINE,  "\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp\");
    
    /**
     * 获得 windows server 中的 terminal server 的端口
     * 也就是远程桌面服务的端口
     * @return
     */
    public static long getTerminalServerPort() {
    	 long port = -1;
    	 
    	 if(rdpKey.hasValues()) {    
    		 RegistryValue portNumber = rdpKey.getValue("PortNumber");
    		 System.out.println(portNumber.toString());	// Name: PortNumber Type: REG_DWORD Value: 3389
    		 String value = portNumber.toString();
    		 port = Long.valueOf(value.substring(value.lastIndexOf(": ") + 2));
    		 System.out.println("port: " + port); 
         }    
    	 
    	 return port;
    }
    
    
    public static void main(String[] args) {
    //	getTerminalServerPort();
    	RegistryKey k=new RegistryKey(LOCALMACHINE,"SYSTEM\\CurrentControlSet\\services");
    	System.out.println( AtiJson.gson(k));
    	/*
    	 * 
    	 * {
  "hKey": -2147483647,
  "name": "services",
  "path": "HKEY_CURRENT_USER\\HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet",
  "handles": [],
  "created": false,
  "level": 4,
  "lastError": 0,
  "view64": 256
}
    	 * 
    	 * */
   // 	k.g
    List<RegistryKey >	 li=k.getSubKeys();
//    k.getSubKeys(".NETFramework")
//    k.getSubKeyNames()
//    k.getNumberOfSubKeys()
    System.out.println(li.size());
    for (RegistryKey registryKey : li) {
    	System.out.println(registryKey.getName() );
    	System.out.println(registryKey.getValue("Description"));
    	System.out.println(registryKey.getValue("Start"));
    	DisplayName
    	ImagePath
	}
    	
    }
    
}